import { useConfig } from "../../hook/D8dConfigProvider.tsx";
import useUploadOss from "../../hook/useUploadOss.ts";
import { App } from "antd";
import MarkEditor from "../MarkEditor/index.tsx";
// import { lazy } from "react";

// const MarkEditor = lazy(() => import("../MarkEditor/index.tsx"));

export default (props: any) => {
  const { getSrc } = useConfig();
  const { message } = App.useApp();
  const { upload } = useUploadOss();
  
  const customUpload = async (file, insertFn) => {
    const msgKey = "" + new Date().getTime();
    upload({
      file: file as Blob,
      //   filename: options.filename as string,
      //   directory:"files/1301/admin_upload/",
      onProgress: () => {
        message.loading({
          key: msgKey,
          content: "上传中...",
          duration: 0,
        });
      },
      onSuccess: (url) => {
        url = getSrc(url);
        console.log("onSuccess", url);
        message.success({
          key: msgKey,
          content: "上传成功",
          duration: 2,
        });
        insertFn(url);
      },
      onError: () => {
        message.error({
          key: msgKey,
          content: "上传失败",
          duration: 2,
        });
      },
    });
  };

  return <MarkEditor {...props} customUpload={customUpload} />;
};
